package com.wlts.wzy.redisLockModule.controller;


import com.wlts.wzy.redisLockModule.config.DistributedLocker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
 
    @Autowired
    private DistributedLocker distributedLocker;


    @RequestMapping("index")
    public String index()throws Exception{

        try {
            distributedLocker.lock("index", () -> {
                try {
                    System.out.println("执行方法！");
                    Thread.sleep(5000);
                }catch (IllegalMonitorStateException e){

                    e.printStackTrace();

                }
                return null;
            },100,2);

        }catch (Exception e){
            return "获取锁失败!";
        }

        return "hello world!";
    }
}